package com.darren.center.design.patterns.handler;

import com.darren.center.design.patterns.command.AbstractHandler;
import com.darren.center.design.patterns.dto.Context;
import com.darren.center.design.patterns.exceptions.ApiBizException;
import com.darren.center.design.patterns.utils.XMLParser;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * <h3>design-patterns</h3>
 * <p>加密校验</p>
 *
 * @author : Darren
 * @date : 2021年06月14日 19:58:17
 **/
@Component
public class VerifyHandler extends AbstractHandler {

    private static Logger logger = LoggerFactory.getLogger(VerifyHandler.class);

    @Value("${oservice.key.expire.time:-1}")
    private String expireTime;


    @Override
    public void processHandler(String reqXml, Context context) {
        try {
            Map<String, Object> xmlMap = XMLParser.getMapFromXML(reqXml);
            String partnerId = (String) xmlMap.get("partnerId");
            Integer expire =  Integer.valueOf(StringUtils.trim(expireTime));

        } catch (ApiBizException e) {
            logger.error("sequence:{}，: 验证不通过{}", context.getMsgSeq(), e);
            throw new ApiBizException(e.getCode(), e.getMsg());
        } catch (Exception e) {
            logger.error("sequence:{}，: 验证不通过,异常{}", context.getMsgSeq(), e);
            throw new ApiBizException(ApiBizException.DEFAULT_CODE, "未知异常,请重试");
        }
    }

}

